package com.ppch.zerocodegenerator.ai.service_factory;

import com.ppch.zerocodegenerator.ai.service.AiCodeGenTypeRoutingService;
import com.ppch.zerocodegenerator.langgraph4j.utils.SpringContextUtil;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.service.AiServices;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Package:ZeroCodeGenerator
 * ClassName:AiCodeGenTypeRoutingServiceFactory
 *
 * @Author 泡泡茶壶
 * @Create 2025/10/21 14:23
 * @Version 1.0
 * Description:
 * 代码生成模式路由：使用 AI 大模型来根据用户提示词选择合适的代码生成模式
 */

@Configuration
@Slf4j
public class AiCodeGenTypeRoutingServiceFactory {

    /**
     * 创建AI代码生成类型路由服务实例
     * 每次创建 AiCodeGenTypeRoutingService 实例都重新创建一个 ChatModel 实例，支持并发
     */
    public AiCodeGenTypeRoutingService createAiCodeGenTypeRoutingService() {
        // 动态获取多例的路由 ChatModel，支持并发
        ChatModel chatModel = SpringContextUtil.getBean("routingChatModelPrototype", ChatModel.class);
        return AiServices.builder(AiCodeGenTypeRoutingService.class)
                .chatModel(chatModel)
                .build();
    }

    /**
     * 默认提供一个 Bean
     */
    @Bean
    public AiCodeGenTypeRoutingService aiCodeGenTypeRoutingService() {
        return createAiCodeGenTypeRoutingService();
    }

}
